package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.GetTrackInventionsEvent;
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.QuarterInventionVO;
	import net.optix.ip.vo.TrackDocketVO;
	import net.optix.ip.vo.TrackClientVO;

	public class GetTrackInventionsCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:GetTrackInventionsEvent	=	GetTrackInventionsEvent(event);
			var delegate:InventionDelegate	=	new InventionDelegate();
			delegate.getTrackInventions(this,myEvent.clientID);
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			/*trace(event.result+" trace e");
			try
			{
				var result:XML		=	event.result;
				
				model.quarters	=	QuarterInventionVO.purseInvention(result);		
			}
			catch(error:Error)
			{
				
			}*/
			
			try
			{
				var result:XML		=	event.result;
				var tracks:ArrayCollection	=	TrackDocketVO.purseTracks(result);
				
				model.quarters	=	TrackClientVO.purseFirst(tracks);
			}
			catch(error:Error)
			{
				trace(error.getStackTrace());
			}
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			trace(event.fault);
		}

	}
}